package com.algorithm.cjm.july.chapter1.ch2;

/**
 * 位运算
 *
 * Created by jieming.chen on 2020/1/11
 */
public class StringContain4 {

    static StringContain4 object = new StringContain4();

    public static void main(String[] args) {
        String a = "bacdefg";
        String b = "w";
        boolean c = object.stringContain(a, b);
        System.out.println(c);

        String a1 = "bacdefg";
        String b1 = "b";
        boolean c1 = object.stringContain(a1, b1);
        System.out.println(c1);
    }

    /**
     * 位运算
     *
     * @param a
     * @param b
     * @return
     */
    private boolean stringContain(String a, String b) {
        int hash = 0;
        for (int i = 0; i < a.length(); i++) {
            hash |= 1 << (a.charAt(i) - 'a');
        }
        for (int i = 0; i < b.length(); i++) {
            if ((hash & (1 << (b.charAt(i) - 'a'))) == 0) {
                return false;
            }
        }
        return true;
    }

}
